package ms.unicorn.dsl.eistar.reasoning.maxbelief;

import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.Resource.Diagnostic;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;

import eistar.EistarPackage;
import eistar.Entity;
import eistar.EvolutionRule;
import eistar.Model;
import eistar.Situation;

import ms.unicorn.EIstarStandaloneSetup;

public class test {

	public static void test1(Situation sit, String ruleName) {
		MaxBeliefReasoning reasoning = new MaxBeliefReasoning();
		EvolutionRule rule1 = sit.getEntity(ruleName);
		MaxBeliefTable table = reasoning.evaluateMaxBelief(rule1);
		table.printTableContent(System.out);
	}

	
	public static Situation loadSituation(String input) {
		ResourceSet rs = new ResourceSetImpl();
		Resource resource = rs.getResource(URI.createURI(input), true);
		EObject eobj = resource.getContents().get(0);
		EList<Diagnostic> errors = resource.getErrors();
		if (errors.size() > 0) {
			for(Diagnostic err: errors) 
				System.out.printf("Error: %s", err.getMessage());
			System.exit(1);
		}
		
		return (Situation) eobj;
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		EistarPackage einstance = EistarPackage.eINSTANCE; // register EistarPackage
		new EIstarStandaloneSetup().createInjectorAndDoEMFRegistration();
		String input = "../rt-unicorn/Test/test2.eis";
		
		Situation sit = loadSituation(input);
		
		MaxBeliefTable tb = new MaxBeliefTable();
		tb.generateFromModel((Model) sit.getEntity("Example2.ERM.rule2.RM8"));
		tb.printTableContent(System.out);
		
		//test1(sit, "Example2.ERM.rule2");
	}

}
